#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
void menu()
{
	printf("************************\n");
	printf("****  1.Add  2.Sub  ****\n");
	printf("****  3.Mul  4.Div  ****\n");
	printf("****  0.exit        ****\n");
}
int Add(int x, int y)
{
	return x + y;
}
int Sub(int x, int y)
{
	return x - y;
}
int Mul(int x, int y)
{
	return x * y;
}
int Div(int x, int y)
{
	return x / y;
}
int main()
{
	int x = 0;
	int y = 0;
	int input;
	do
	{
		menu();
		int(*pfArr[])(int, int) = { 0,Add,Sub,Mul,Div };
		printf("请选择:>");
		scanf("%d", &input);
		if (input == 0)
		{
			printf("退出计算器\n");
			break;
		}
		else if (input >= 1 && input <= 4)
		{
			printf("请输入两个操作数:>");
			scanf("%d%d", &x, &y);
            //函数指针数组用途：转移表
			int ret = pfArr[input](x, y);
			printf("计算结果是%d\n", ret);
		}
		else
		{
			printf("输入错误\n");
		}
	} while (input);
	return 0;
}